<template>
    <div class="demo">
        <h2>学校名称：{{name}}</h2>
        <h2>地址：{{address}}</h2>
	</div>
</template>

<script>
    import PubSub from 'pubsub-js';
    export default {
        name:'School',
        data(){
           return {
            name:'广师大',
            address:'广州天河区'
           }
        },
        methods:{
            getData(msgName,data){
                console.log('接收到的数据为：',data)
            }
        },
        mounted(){
            // 订阅消息
            this.pubId = PubSub.subscribe('hello',this.getData)
        },
        beforeDestroy(){
            // 取消订阅
            PubSub.unsubscribe(this.pubId)
        }
    }
</script>
<style scoped>
    .demo{
        background-color: green;
    }
</style>